import pefile

def get_exported_functions(dll_path):
    try:
        # 使用 pefile 加载 DLL 文件
        pe = pefile.PE(dll_path)

        # 检查是否有导出表
        if not hasattr(pe, 'DIRECTORY_ENTRY_EXPORT'):
            print(f"{dll_path} 没有导出函数。")
            return []

        # 获取导出表中的函数名
        exported_functions = []
        for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols:
            if exp.name:
                exported_functions.append(exp.name.decode('utf-8'))
            else:
                exported_functions.append(f"Ordinal_{exp.ordinal}")

        pe.close()
        return exported_functions
    except Exception as e:
        print(f"无法解析DLL文件: {e}")
        return []

if __name__ == "__main__":
    dll_path = "example.dll"  # 替换为你的DLL文件路径
    functions = get_exported_functions(dll_path)
    if functions:
        print(f"{dll_path} 导出的函数名如下:")
        for func in functions:
            print(func)
    else:
        print(f"{dll_path} 没有导出函数或无法读取。")
